class RepairStatesController < ApplicationController
  # GET /repair_states
  # GET /repair_states.xml
  layout "backend"
  def index
    @repair_states = RepairState.find(:all)
  end

  # GET /repair_states/1
  # GET /repair_states/1.xml
  def show
    @repair_state = RepairState.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @repair_state }
    end
  end

  # GET /repair_states/new
  # GET /repair_states/new.xml
  def new
    @repair_state = RepairState.new

    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @repair_state }
    end
  end

  # GET /repair_states/1/edit
  def edit
    @repair_state = RepairState.find(params[:id])
  end
  def set_repair_states
    RepairState.delete_all
    10.times { |n| RepairState.find_or_create_by_id(n+1) }
    RepairState.update( 1, :name => "Ready for Pickup", :short_name => "rfp" ) #Ready for Pickup
    RepairState.update( 2, :name => "Awaiting Callback", :short_name => "awc" ) #Ready for Pickup
    RepairState.update( 3, :name => "In Repair", :short_name => "open" ) #Ready for Pickup
    RepairState.update( 4, :name => "Parts Allocated", :short_name => "open" ) #Ready for Pickup
    RepairState.update( 5, :name => "Open", :short_name => "open" ) #Ready for Pickup
    RepairState.update( 6, :name => "Awaiting Parts", :short_name => "awp" ) #Ready for Pickup
    RepairState.delete( 7 ) # doesn't exist
    RepairState.update( 8, :name => "Cancelled", :short_name => "closed" ) #Ready for Pickup
    RepairState.update( 9, :name => "Closed", :short_name => "closed" ) #Ready for Pickup
    RepairState.update( 10, :name => "Awaiting Unit", :short_name => "awu" ) #Ready for Pickup
    redirect_to :controller => "repair_states"
  end
  # POST /repair_states
  # POST /repair_states.xml
  def create
    @repair_state = RepairState.new(params[:repair_state])

      if @repair_state.save
        flash[:notice] = 'RepairState was successfully created.'
        redirect_to :action => "index"
      else
        redirect_to :action => "index"
      end
  end

  # PUT /repair_states/1
  # PUT /repair_states/1.xml
  def update
    @repair_state = RepairState.find(params[:id])

      if @repair_state.update_attributes(params[:repair_state])
        redirect_to :action => "index"
      else
        redirect_to :action => "index"
      end
  end

  # DELETE /repair_states/1
  # DELETE /repair_states/1.xml
  def destroy
    @repair_state = RepairState.find(params[:id])
    @repair_state.destroy

    respond_to do |format|
      format.html { redirect_to(repair_states_url) }
      format.xml  { head :ok }
    end
  end
end
